package com.aaa.service.impl;

import com.aaa.dao.Test_plan_fpaDao;
import com.aaa.entity.Test_plan;
import com.aaa.service.Test_plan_fpaService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class Test_plan_fpaServiceImpl implements Test_plan_fpaService {

    @Autowired
    private Test_plan_fpaDao plan_fpaDao;

    /**
    * @Author: WTH
    * @Description: 查询，分页，
    * @Date:2022-07-01 15:03
    * @Params:
    */
    @Override
    public Page<Test_plan> selectFpaPlan(Test_plan plan_fpa) {
        Page<Test_plan> page = PageHelper.startPage(plan_fpa.getPage(), plan_fpa.getLimit());
        List<Test_plan> test_plan_fpas = plan_fpaDao.selectFpaPlan(plan_fpa);
        Page fpa= (Page) test_plan_fpas;
        return fpa;
    }

    /**
    * @Author: WTH
    * @Description: 新增,随机生成6位数
    * @Date:2022-07-01 15:03
    * @Params:
    */
    @Override
    public Enum01 addFpaPlan(Test_plan plan_fpa) {
        Random six=new Random();
        String results="";
        for(int a=0;a<6;a++){
            //.nextInt(10),随机生成0-10之间的随机正整数，不包含10
            results=results+six.nextInt(10);
        }
        Integer result=Integer.parseInt(results);
        plan_fpa.setTest_code(result);
        int i = plan_fpaDao.addFpaPlan(plan_fpa);
        if(i>0){
            return Enum01.SUCCESS;
        }
        return Enum01.FAIL;
    }

    /**
    * @Author: WTH
    * @Description: 删除
    * @Date:2022-07-01 15:52
    * @Params:
    */
    @Override
    public boolean deleteFpaPlan(String id) {
        int i = plan_fpaDao.deleteFpaPlan(id);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-01 16:02
    * @Params:
    */
    @Override
    public Enum01 updateFpaPlan(Test_plan plan_fpa) {
        int i = plan_fpaDao.updateFpaPlan(plan_fpa);
        if(i>0){
            return Enum01.SUCCESS;
        }
        return Enum01.FAIL;
    }

    @Override
    public Test_plan selectByCode(Integer test_code) {
        Test_plan test_plan = plan_fpaDao.selectByCode(test_code);
        return test_plan;
    }
}
